from python_baway.common.xcommon import sep


class Person:
    __country = '中国'

    @staticmethod
    def show_static_info():
        print('We Should Study As Hard As We Could!')

    @classmethod
    def get_default_country(cls):
        return cls.__country

    @classmethod
    def set_default_country(cls, country):
        cls.__country = country

    @classmethod
    def show_cls_info(cls):
        cls.show_static_info()
        print(f'Person.__country: {cls.get_default_country()}')

    def __init__(self):
        self.__name = None
        self.__province = None

    def __del__(self):
        print(f'Destructing Person {self.__name} from {self.__country} - {self.__province}')

    def __str__(self):
        return '''\
{{ Person: 姓名 {name}; 国籍 {country}; 省份 {province}; 默认国籍 {def_c} }}\
'''.format(name=self.__name,
           country=self.__country,
           province=self.__province,
           def_c=Person.__country)

    def set_name(self, name):
        self.__name = name

    def set_province(self, province):
        self.__province = province

    def set_country(self, country):
        self.__country = country

    def get_name(self):
        return self.__name

    def get_province(self):
        return self.__province

    def get_country(self):
        return self.__country

    def info(self):
        print('''\
姓名 {name}
国籍 {country}
省份 {province}
默认国籍 {def_c}
'''.format(name=self.__name,  # Remember this, python is python, not java, self.get_name() may have no extra advantage.
           country=self.__country,
           province=self.__province,
           def_c=Person.__country))


if '__main__' == __name__:
    sep(label='Person')
    print(Person.get_default_country())
    Person.set_default_country('Japan')
    print(Person.get_default_country())
    Person.show_cls_info()

    sep(label='xiaoyi')
    xiaoyi = Person()
    print(xiaoyi)
    xiaoyi.set_default_country('Ukubania')
    xiaoyi.info()
    xiaoyi.set_name('小一')
    xiaoyi.set_province('新疆')
    xiaoyi.set_country('USA')
    xiaoyi.info()
    print(xiaoyi)
    del xiaoyi
    print(Person.get_default_country())
    sep(label='End of testing Person')


class Student(object):

    def __init__(self, id, name):
        self.__id = id
        self.__scores = {}
        self.__name = name

    def __del__(self):
        print(f'Destructing Student "{self.__name}" with id {self.__id}')

    def __str__(self):
        return f'{{ Student: "{self.__name}" with id {self.__id} with scores: {self.__scores} }}'

    def get_scores(self):
        return self.__scores

    def set_scores(self, subject, score):
        self.__scores[subject] = score


if '__main__' == __name__:
    sep(label='xiaoer')
    xiaoer = Student('12345678', '小二')
    print(xiaoer)
    xiaoer.set_scores('English', 67)
    xiaoer.set_scores('Computer', 88.88)
    print(xiaoer.get_scores())
    'By decorator:'
    print(xiaoer)

    sep(label='End of testing Student')
